package com.game.astd.spirit;

import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

import com.game.astd.spirit.model.UserData;

public class GameUserInfoUtil
{
	private static ConcurrentHashMap<Integer, UserData> userInfoCache = new ConcurrentHashMap<Integer, UserData>();
	private static AtomicBoolean isUserLoadSuc = new AtomicBoolean(false);

	public static Iterator<Integer> userIte()
	{
		return userInfoCache.keySet().iterator();
	}

	public static UserData getUser(int gid)
	{
		return userInfoCache.get(gid);
	}

	public static void putUser(int gid, UserData u)
	{
		if (!userInfoCache.containsKey(gid))
		{
			userInfoCache.put(gid, u);
		}
	}

	public static void removeUser(int gid)
	{
		userInfoCache.remove(gid);
	}

	public static boolean getIsUserLoadSuc()
	{
		return isUserLoadSuc.get();
	}

	public static void setIsUserLoadSuc(boolean isUserLoadSuc)
	{
		GameUserInfoUtil.isUserLoadSuc.set(isUserLoadSuc);
	}

	/**
	 * 获取游戏昵称信息
	 * 
	 * @param username
	 * @return
	 */
	public static String getGameName(int gid)
	{
		if (userInfoCache.containsKey(gid))
		{
			return userInfoCache.get(gid).getGameInfo("game_nick_name");
		}
		return "";
	}
}
